
var firstImg = document.querySelector( "img" );

var dataForWeixin = {
  appId: "",
  MsgImg: "",
  TLImg: "",
  url: document.location.href,
  title: document.title,
  desc: "",
  fakeid: "",
  callback:function(){}
};

if ( firstImg ) {
  var src = firstImg.getAttribute( "src" ),
      index = src.indexOf( "http://" ) || "";
  dataForWeixin.MsgImg = src.substr( index );
  dataForWeixin.TLImg = src.substr( index );
};

(function(){

   var onBridgeReady = function(){

   WeixinJSBridge.on("menu:share:appmessage", function(argv){

      WeixinJSBridge.invoke("sendAppMessage",{

         "appid":dataForWeixin.appId,

         "img_url":dataForWeixin.MsgImg,

         "img_width":"120",

         "img_height":"120",

         "link":dataForWeixin.url,

         "desc":dataForWeixin.desc,

         "title":dataForWeixin.title

      }, function(res){(dataForWeixin.callback)();});

   });

   WeixinJSBridge.on("menu:share:timeline", function(argv){

      (dataForWeixin.callback)();

      WeixinJSBridge.invoke("shareTimeline",{

         "img_url":dataForWeixin.TLImg,

         "img_width":"120",

         "img_height":"120",

         "link":dataForWeixin.url,

         "desc":dataForWeixin.desc,

         "title":dataForWeixin.title

      }, function(res){});

   });
  };
  document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
})();